﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnimalFight.Lib.Interfaces;
using AnimalFight.Lib.EventHandlers;

namespace AnimalFight.Lib.Data
{
    public class Horse : AnimalBase, IDefend, IAttackable
    {
        public event DefendDelegate DefendEvent;

        public bool IsDefending { get; set; }

        public void Defend()
        {
            if (DefendEvent != null)
            {
                DefendEvent(this, new DefendEventHandler
                {
                    AnimalName = this.Name,
                    Target = Animals.Horse
                });
            }
        }

        public override void Escape()
        {
            this.HasEscaped = true;
            Console.WriteLine("Horse has escaped");
        }

        public void Attacked(int ap)
        {
            if (this._hasEscaped)
            {
                Console.WriteLine("{0} has escaped. Cannot be attacked.", this.Name);
            }
            else if (this._isDead)
            {
                Console.WriteLine("{0} has already dead. Cannot be attacked.", this.Name);
            }
            else
            {
                Console.WriteLine("{0} has been attacked. Current HP = {1}", this.Name, this.HP);

                int realDP = this.IsDefending ? this.DP + 10 : this.DP;

                this.HP -= (ap - realDP);

                Console.WriteLine("HP is decreased -{1}", this.Name, ap - this.DP);
                Console.WriteLine("Current HP = {0}", this.HP);

                if (this.HP <= 0)
                {
                    this.IsDead = true;
                }
            }
        }
    }
}
